home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / yacc / occam.lha / occam / occam.y < prev    next >
Text File  |  1989-08-22  |  4KB  |  281 lines

  1. /* 
  2.  *
  3.  *        OCCAM yacc specification
  4.  *
  5.  *        Peter Polkinghorne - GEC Research
  6.  *
  7.  */
  8.  
  9. /*
  10.  * This work is in the public domain.
  11.  * It was written by Peter Polkinghorne in 1986 & 1989 at
  12.  * GEC Hirst Research Centre, Wembley, England.
  13.  * No liability is accepted or warranty given by the Author,
  14.  * still less my employers.
  15.  */
  16.  
  17. /* revision history
  18.     0.0    initial attempt                pjmp    22/7/86
  19.     0.1    add in COMMA so that yylex can cope with
  20.         comma differentiation for PROC decls    pjmp    4/8/86
  21.     0.2    add in main - since BSD does not have -ly
  22.                             pjmp    8/3/89
  23.  
  24. end revisions */
  25.  
  26. %token        VAR    CHAN    ANY    WAIT    SKIP    ID    EOL
  27. %token        VALUE    BYTE    DEF    PROC    NOT    NUMBER    BOOL
  28. %token        NOW    TABLE    BOOLOP    SHIFTOP    COMPOP    CHCON    STR
  29. %token        LOGOP    SEQ    ALT    IF    PAR    WHILE    FOR
  30. %token        BEG    END    COMMA
  31.  
  32. %start        program
  33.  
  34. %%
  35.  
  36. program        :    sep process
  37.         |    process
  38.         ;
  39.  
  40. process        :    primitive sep
  41.         |    ID sep
  42.         |    ID '(' explist ')' sep
  43.         |    construct
  44.         |    declaration ':' sep process
  45.         |    error sep
  46.             {
  47.                 yyerrok;
  48.             }
  49.         ;
  50.  
  51. primitive    :    assignment
  52.         |    input
  53.         |    output
  54.         |    wait
  55.         |    skip
  56.         ;
  57.  
  58.  
  59. construct    :    SEQ sep BEG proclist END
  60.         |    SEQ replic sep BEG process END
  61.         |    SEQ sep
  62.         |    PAR sep BEG proclist END
  63.         |    PAR replic sep BEG process END
  64.         |    PAR sep
  65.         |    IF sep BEG condlist END
  66.         |    IF replic sep BEG cond END
  67.         |    IF sep
  68.         |    ALT sep BEG guardplist END
  69.         |    ALT replic sep BEG guardp END
  70.         |    ALT sep
  71.         |    WHILE expr sep BEG process END
  72.         ;
  73.  
  74. sep        :    EOL
  75.         |    sep EOL
  76.         ;
  77.  
  78. proclist    :    process
  79.         |    proclist process
  80.         ;
  81.  
  82. condlist    :    cond
  83.         |    condlist cond
  84.         ;
  85.  
  86. guardplist    :    guardp
  87.         |    guardplist guardp
  88.         ;
  89.  
  90.  
  91. replic        :    ID '=' '[' expr FOR expr ']'
  92.         ;
  93.  
  94. cond        :    expr sep BEG process END
  95.         |    IF sep
  96.         |    IF sep BEG condlist END
  97.         |    IF replic sep BEG cond END
  98.         ;
  99.  
  100. guardp        :    guard sep BEG process END
  101.         |    ALT sep
  102.         |    ALT sep BEG guardplist END
  103.         |    ALT replic sep BEG guardp END
  104.         ;
  105.  
  106. guard        :    expr '&' input
  107.         |    input
  108.         |    expr '&' wait
  109.         |    wait
  110.         |    expr '&' SKIP
  111.         |    SKIP
  112.         ;
  113.  
  114. declaration    :    VAR varlist
  115.         |    CHAN chanlist
  116.         |    DEF deflist
  117.         |    PROC ID '=' sep BEG process END 
  118.         |    PROC ID formparms '=' sep BEG process END
  119.         ;
  120.  
  121. assignment    :    var ':' '=' expr
  122.         ;
  123.  
  124. input        :    chan '?' inlist
  125.         |    chan '?' ANY
  126.         ;
  127.  
  128. output        :    chan '!' outlist
  129.         |    chan '!' ANY
  130.         ;
  131.  
  132. wait        :    WAIT expr
  133.         ;
  134.  
  135. skip        :    SKIP
  136.         ;
  137.  
  138. inlist        :    var
  139.         |    inlist ';' var
  140.         ;
  141.  
  142. outlist        :    expr
  143.         |    outlist ';' expr
  144.         ;
  145.  
  146. explist        :    expr
  147.         |    explist ',' expr
  148.         ;
  149.  
  150. varlist        :    var
  151.         |    varlist ',' var
  152.         ;
  153.  
  154. chanlist    :    chan
  155.         |    chanlist ',' chan
  156.         ;
  157.  
  158. deflist        :    def
  159.         |    deflist ',' def
  160.         ;
  161.  
  162. formparms    :    '(' fparmlist ')'
  163.         ;
  164.  
  165. fparmlist    :    fparm
  166.         |    fparmlist COMMA fparm
  167.         ;
  168.  
  169. var        :    ID
  170.         |    ID subscript
  171.         ;
  172.  
  173. chan        :    ID
  174.         |    ID '[' expr ']'
  175.         ;
  176.  
  177. def        :    ID '=' expr
  178.         |    ID '=' veccon
  179.         ;
  180.  
  181. subscript    :    '[' expr ']'
  182.         |    '[' BYTE expr ']'
  183.         ;
  184.  
  185.  
  186. fparm        :    VAR plist
  187.         |    CHAN plist
  188.         |    VALUE plist
  189.         ;
  190.  
  191. plist        :    parm
  192.         |    plist ',' parm
  193.         ;
  194.  
  195. parm        :    ID
  196.         |    ID '[' ']'
  197.         ;
  198.  
  199. expr        :    monop element
  200.         |    element op element
  201.         |    ellist
  202.         ;
  203.  
  204. ellist        :    element
  205.         |    ellist assop element
  206.         ;
  207.  
  208. monop        :    '-'
  209.         |    NOT
  210.         ;
  211.  
  212. element        :    NUMBER
  213.         |    BOOL
  214.         |    NOW
  215.         |    CHCON
  216.         |    '(' expr ')'
  217.         |    item
  218.         ;
  219.  
  220. op        :    arop
  221.         |    COMPOP
  222.         |    '='
  223.         |    SHIFTOP
  224.         ;
  225.  
  226. assop        :    '+'
  227.         |    '*'
  228.         |    LOGOP
  229.         |    BOOLOP
  230.         ;
  231.  
  232. arop        :    '-'
  233.         |    '/'
  234.         |    '\\'
  235.         ;
  236.  
  237. item        :    ID
  238.         |    ID subscript
  239.         |    veccon subscript
  240.         ;
  241.  
  242. veccon        :    str
  243.         |    TABLE '[' BYTE tlist ']'
  244.         |    TABLE '[' tlist ']'
  245.         ;
  246.  
  247.  
  248. str        :    STR
  249.         |    str sep STR
  250.         ;
  251.  
  252. tlist        :    expr
  253.         |    tlist ',' expr
  254.         ;
  255.  
  256. %%
  257.  
  258. #include <stdio.h>
  259.  
  260. void main()
  261. {
  262.  
  263.     exit( yyparse() );
  264.  
  265. }/*main*/
  266.  
  267. yyerror( str )
  268. char     *str;
  269. /* our slightly more informative error routine */
  270. {
  271.  
  272. extern int    yylineno;
  273. extern char    yytext[];
  274.  
  275.     fprintf( stderr, "ERROR <%s> near <%s> on line %d\n",
  276.             str, yytext, yylineno );
  277.  
  278. }/*yyerror*/
  279.  
  280. /*end occam.y*/
  281.